<div class="demo-content">    
    <!-- 表单页 ================================================== --> 
    <div class="row">
      <div class="span24">
        <h2>添加管理字段</h2>
        <hr />
        <?php $form=$this->beginWidget('CActiveForm', array(
            'id'=>'modelfield-_form-form',
            'enableAjaxValidation'=>false,
            'enableClientValidation'=>false,
            'clientOptions'=>array(  
                'validateOnSubmit'=>false,  
             ),
             'htmlOptions'=>array('class'=>'form-horizontal')
        )); ?>
            <div class="control-group">
              <label class="control-label"><s>*</s><?php echo $this->_attributeFieldLabels['form_type'] ?>：</label>
              <div class="controls">
              <?php
                $aFormType = array(
                    ''=>'请选择字段类型',
                    'text'=>'单行文本',
                    'textarea'=>'多行文本',
                    'editor'=>'编辑器',
                    'box'=>'选项',
                    'image'=>'图片上传',
                    'datetime' => '日期和时间',
                    'area' => '区域选择'
                );
                echo $form->dropDownList($this->oModelField ,'form_type',$aFormType,array('class'=>'input-normal' ,'data-rules'=>'{required:true}' ,'onChange'=>'fieldChange(this.value)'));
              ?>
                
              </div>
            </div>
            <div class="control-group">
              <label class="control-label"><s>*</s><?php echo $this->_attributeFieldLabels['field'] ?>：</label>
              <div class="controls">
                <?php echo $form->textField($this->oModelField ,'field' ,array('class'=>'input-middle' ,'data-rules'=>'{required:true}'))  ?>
                <span class="auxiliary-text">只能由英文字母和下划线组成，并且仅能字母开头，不以下划线结尾</span>
              </div>
            </div>
 
            <div class="control-group">
              <label class="control-label"><s>*</s><?php echo $this->_attributeFieldLabels['field_name'] ?>：</label>
              <div class="controls">
                <?php echo $form->textField($this->oModelField ,'field_name' ,array('class'=>'input-middle' ,'data-rules'=>'{required:true}'))  ?>
                <span class="auxiliary-text">例如：文章标题</span>
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">相关设置：</label>
              <div class="controls control-row-auto settings">
              </div>
            </div> 
            <div class="control-group">
              <label class="control-label"><?php echo $this->_attributeFieldLabels['length']; ?>：</label>
              <div class="controls">
                <?php echo $this->_attributeFieldLabels['min_length'] . ':' .$form->textField($this->oModelField ,'min_length' ,array('class'=>'width40'));  ?>
                <?php echo $this->_attributeFieldLabels['max_length'] . ':' .$form->textField($this->oModelField ,'max_length' ,array('class'=>'width40'));  ?>
              </div>
            </div>
 
            <div class="control-group">
              <label class="control-label"><?php echo $this->_attributeFieldLabels['pattern']; ?>：</label>    
              <div class="controls">
                <?php 
                    echo $form->textField($this->oModelField ,'pattern' ,array('class'=>'input-normal pattern-txt'));
                    //选择
                    $aPattern = array(
                        '' => '常用正则',
                        '/^[0-9.-]+$/' => '数字',
                        '/^[0-9-]+$/' => '整数',
                        '/^[a-z]+$/i' => '字母',
                        '/^[0-9a-z]+$/i' => '数字+字母',
                        '/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/' => 'E-mail地址',
                        '/^(1)[0-9]{10}$/' => '手机号码',
                        '/^[0-9-]{6,13}$/' => '电话号码',
                        '/^[0-9]{6}' => '邮政编码',
                        '/^http:\/\//' => '超级链接'
                    );
                    echo "&nbsp;&nbsp;" .Form::select($aPattern ,'' ,'class="pattern-change"');
                    //echo $form->dropDownList($this->oModelField ,'form_type',$aPattern,array('class'=>'input-normal pattern-change'));
                ?>
              </div>
            </div>            
            <div class="control-group">
              <label class="control-label"><?php echo $this->_attributeFieldLabels['isshow']; ?>：</label>
              <div class="controls">
                <?php echo $form->radioButtonList($this->oModelField ,'isshow' ,array('1'=>'是','2'=>'否') ,array('separator'=>'&nbsp;'));  ?>
              </div>
            </div>
            <hr>
            <div class="form-actions span5 offset3">
               <?php echo CHtml::submitButton('提交',array('class'=>'button button-success'));?>
	           <?php echo CHtml::link('返回字段管理',$this->createUrl('model/modelfield' ,array('model_id'=>$iModelId)),array('class'=>'button button-primary'));?>
            </div>
        <?php $this->endWidget(); ?> 
      </div>
    </div>  
    <script type="text/javascript">
        var Form = BUI.Form;
      
        var form = new Form.Form({
            srcNode : '#modelfield-_form-form'
        }).render();
        var  aField = form.getField('CmsModelField[field_name]') ,bField = form.getField('CmsModelField[field]');
          bField.set('remote',{
             url : '<?php echo $this->createUrl('model/ajaxVerifyField') ?>',
             dataType:'json',//默认为字符串
             callback : function(data){
               if(data.success){
                return '';
               }else{
                return data.msg;
               }
             }
          });
          aField.set('remote',{
             url : '<?php echo $this->createUrl('model/ajaxVerifyFieldName') ?>',
             dataType:'json',//默认为字符串
             callback : function(data){
               if(data.success){
                return '';
               }else{
                return data.msg;
               }
             }
          });
          
      $('.pattern-change').bind('change' ,function(){
            $('.pattern-txt').val($(this).val());
      });
      function fieldChange(filetype){
        var url = '<?php echo $this->createUrl('model/fieldtype') ?>'+ '?fieldtype='+filetype;
        $.getJSON(url ,function(jData){
            $('.settings').html(jData.data);
        });
      }
    </script>
<!-- script end -->
  </div>